package com.example.designpatterns.singleton;

/**
 * 静态内部类方式
 * jvm保证单例:jvm只加载一次类,内部类不会被加载
 * 加载外部类时，不会加载内部类，这样实现懒加载
 */
public class Mgr05 {
    private Mgr05() {
    }

    private static class Mgr05Holder {
        private final static Mgr05 INSTANCE = new Mgr05();
    }

    public static Mgr05 getInstance() {
        return Mgr05Holder.INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                System.out.println(Mgr05.getInstance().hashCode());
            }).start();
        }
    }
}
